﻿using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VioletDevelopmentLaboratory.Net.Web;
using VioletDevelopmentLaboratory.Net.Web.Component;

public partial class vboard_component_board_template_default_view_sub_thread : BoardSubPartBase
{
	private BoardThread CurrentThread;
	private AttachmentFileInfoCollection CurrentAttachmentFileInfoCollection;

	private String getAutoMediaFileViewHtml()
	{
		String mediaHtml = "";
		String description = "";

		foreach (AttachmentFileInfo fileInfo in this.CurrentAttachmentFileInfoCollection)
		{
			if (fileInfo.UploadFile.PhysicalFile.Exists)
			{
				if (!String.IsNullOrEmpty(fileInfo.UploadFile.Description))
					description = "[" + fileInfo.UploadFile.Description + "]";

				if (fileInfo.UploadFile.ContentType.IndexOf("image") > -1)
				{
					String url = BoardUtil.GetAttachmentFileViewUrl(base.CurrentBoard.ComponentID, fileInfo.FileID);
					mediaHtml += String.Format(VUtility.GetVWebGlobalResource("General_Script_ImageView"), url.Replace("&", "&amp;"), url.Replace("&", "&amp;"), description);
				}
				else if (fileInfo.UploadFile.ContentType.IndexOf("quicktime") > -1)
				{
					mediaHtml += String.Format(VUtility.GetVWebGlobalResource("General_Script_QuickTimePlayer"), BoardUtil.GetAttachmentFileViewUrl(base.CurrentBoard.ComponentID, fileInfo.FileID).Replace("&", "&amp;"), description);
				}
				else if (fileInfo.UploadFile.ContentType.IndexOf("video") > -1 || fileInfo.UploadFile.ContentType.IndexOf("audio") > -1)
				{
					mediaHtml += String.Format(VUtility.GetVWebGlobalResource("General_Script_WindowsMediaPlayer"), BoardUtil.GetAttachmentFileViewUrl(base.CurrentBoard.ComponentID, fileInfo.FileID).Replace("&", "&amp;"), description);
				}
				else if (fileInfo.UploadFile.ContentType.IndexOf("flash") > -1)
				{
					mediaHtml += String.Format(VUtility.GetVWebGlobalResource("General_Script_FlashPlayer"), BoardUtil.GetAttachmentFileViewUrl(base.CurrentBoard.ComponentID, fileInfo.FileID).Replace("&", "&amp;"), description);
				}
			}
		}

		return mediaHtml;
	}



	protected void Page_Init(Object sender, EventArgs e)
	{
		this.CurrentThread = (BoardThread)this.Page.Items["CurrentThread"];
		this.CurrentAttachmentFileInfoCollection = (AttachmentFileInfoCollection)this.Page.Items["CurrentAttachmentFileInfoCollection"];
	}

	protected void Page_Load(object sender, EventArgs e)
	{
		if (!Page.IsPostBack)
		{
			if (!this.CurrentThread.IsDeleted)
				this.CurrentThread.ModifyReadCount(1);

			Page.Title += " - " + this.CurrentThread.Title;
			TitleLiteral.Text = this.CurrentThread.Title;

			ContentLiteral.Text = this.CurrentThread.IsHtml ? this.CurrentThread.Content : Server.HtmlEncode(this.CurrentThread.Content).Replace("\r\n", "<br />");

			ThreadDetailInfoLiteral.Text = String.Format(GetLocalResourceObject("ThreadView_DetailInfoFormat").ToString(),
				this.CurrentThread.RegistrationDate, this.CurrentThread.IP, this.CurrentThread.ReadCount);

			if (!this.CurrentThread.IsDeleted)
			{
				if (!String.IsNullOrEmpty(this.CurrentThread.LastUpdateBy))
				{
					ThreadUpdateInfoLiteral.Text = String.Format(GetLocalResourceObject("ThreadView_UpdateInfoFormat").ToString(),
						this.CurrentThread.LastUpdateBy, this.CurrentThread.LastUpdateDate);
				}

				if (!String.IsNullOrEmpty(BoardParameters.SearchText))
				{
					TitleLiteral.Text = TitleLiteral.Text.Replace(BoardParameters.SearchText, String.Format(VUtility.GetVWebGlobalResource("General_SearchTextFormat"), BoardParameters.SearchText));
					ContentLiteral.Text = ContentLiteral.Text.Replace(BoardParameters.SearchText, String.Format(VUtility.GetVWebGlobalResource("General_SearchTextFormat"), BoardParameters.SearchText));
				}
			}

			if (!this.CurrentThread.IsDeleted && !this.CurrentThread.IsBlocked)
			{
				//카테고리
				if (!String.IsNullOrEmpty(this.CurrentThread.CategoryName))
					CategoryLiteral.Text = String.Format(GetLocalResourceObject("ThreadView_CategoryFormat").ToString(), this.CurrentThread.CategoryName);

				if (this.CurrentAttachmentFileInfoCollection != null)
				{
					if (base.CurrentUserInfo.IsAdministrator || base.CurrentUserInfo.IsSysop(base.CurrentBoard) || base.CurrentUserFileDownload)
					{
						if (this.CurrentThread.AutoMediaFileView)
						{
							AttachmentMultimediaLiteral.Visible = true;
							AttachmentMultimediaLiteral.Text = getAutoMediaFileViewHtml(); ;
						}
						else
						{
							AttachmentMultimediaLiteral.Visible = false;
						}
					}
				}
			}
		}
	}
}
